# -*- coding:utf-8 -*-  
__author__ = 'TenaciousZ'  
  
from Tkinter import *  
from PIL import ImageTk, Image
from tkfuncs import (MenuDIY, FrameDIY, SetTkWindow, 
					test_show_info, test_show_help)
import os  


class MyMenu(MenuDIY):
	def __init__(self, master):
		super(MyMenu, self).__init__(master)

	def init(self):
		self.menu_diy()

	def menu_diy(self):
		optionmenu = Menu(self.menubar, tearoff=1)  
		optionmenu.add_command(label='关于.本程序', command=self.show_info)  
		optionmenu.add_command(label='帮助', command=self.show_help)  
		optionmenu.add_separator()		# 横线
		optionmenu.add_command(label='退出', command=self.master.destroy)  
		self.menubar.add_cascade(label='选项', menu=optionmenu)

	@staticmethod
	def show_info():  
		"""show the software info"""  
		test_show_info()
	@staticmethod
	def show_help():  
		"""show help info"""  
		test_show_help()

class MyFrame(FrameDIY):
	def __init__(self, master):
		super(MyFrame, self).__init__()
		self.image_path = 'wifi.jpg'
		self.master = master

	def init(self):
		self.left_frame_diy()
		pass

	def left_frame_diy(self):
		# self.right_frame = Frame()
		var = IntVar()
		# 标签
		Label(self.master, text="标签1: ").grid(row=0)
		Label(self.master, text="标签2: ").grid(row=1)

		# 输入框
		e1 = Entry(self.master)
		e2 = Entry(self.master)
		e1.grid(row=0, column=1)  
		e2.grid(row=1, column=1)  
		# entry.bind('<Return>', self.get_input, add=1)

		# 多选
		checkbutton = Checkbutton(self.master, text='多选框', variable=var)
		checkbutton.grid(columnspan=2, sticky=W)

		# 图片
		# image = Image.open(self.image_path)  
		image = ImageTk.PhotoImage(file=self.image_path)
		label = Label(image=image)
		label.image = image
		# label.grid(row=0, column=2, columnspan=6, rowspan=6, sticky=W+E+N+S, padx=5, pady=5)

		# 按钮
		b1 = Button(self.master, text='按钮1', command=lambda : self.get_entry_input(e1))
		b2 = Button(self.master, text='按钮2', command=lambda : self.get_entry_input(e2))
		b1.grid(row=7, column=3)
		b2.grid(row=7, column=4)

		# 画布
		self.canvas = Canvas(self.master, width=150, height=40)
		# canvas.create_line(0,0,500,500)
		self.canvas.create_image(0,0,anchor=NW,image=image)
		self.canvas.grid(row=0, column=2, columnspan=6, rowspan=6)

		# 绑定事件
		self.canvas.bind_all('<KeyPress-Up>', self.movetriangle)
		self.canvas.bind_all('<KeyPress-Down>', self.movetriangle)
		self.canvas.bind_all('<KeyPress-Left>', self.movetriangle)
		self.canvas.bind_all('<KeyPress-Right>', self.movetriangle)

	def hello(self):
		self.test_show('hello')

	def get_entry_input(self, entry):
		input = entry.get().strip()
		self.test_show(input)

	def get_input(self, entry):
		input = entry.get().strip()
		self.test_show(input)
	
	def movetriangle(self, event):
		if event.keysym=='Up':
			self.canvas.move(1,0,-3)
		elif event.keysym=='Down':
			self.canvas.move(1,0,3)
		elif event.keysym=='Left':
			self.canvas.move(1,-3,0)
		else:
			self.canvas.move(1,3,0)
	


def a():  
	master = Tk()
	
	# 配置窗口
	my_set = SetTkWindow(master)
	my_set.title = '开发测试'
	my_set.ico_path = 'py.ico'
	my_set.window_size = '500x300+500+200'
	my_set.init()
	# master.resizable(0, 0) 

	# 加载菜单
	my_menu = MyMenu(master)
	my_menu.init()
	master.config(menu=my_menu.menubar)

	# 加载表单
	my_frame = MyFrame(master)
	my_frame.init()

	master.mainloop()  


if __name__ == '__main__':  
	a()